<template>
  <div class="mh-form-box">
    <group>
      <x-input title="账户" v-model="loginName" placeholder="请输入账号"></x-input>
      <x-input title="密码" v-model="password" type="password" placeholder="密码"></x-input>
    </group>
    <group>
      <x-button @click.native="handleSubmit" type="primary">立即登录</x-button>
    </group>
  </div>
</template>

<script>
import Vue from 'vue'
import { Alert, XInput, Group, XButton, Cell } from 'vux'
import qs from 'qs'
import Api from '@/libs/api'

export default {
  components: {
    XInput,
    XButton,
    Group,
    Cell,
    Alert
  },
  mounted() {},
  data() {
    return {
      msg: '视频投票',
      loginName: '',
      password: ''
    }
  },
  methods: {
    handleSubmit() {
      let vue = this
      let paramLogin = {
        loginName: this.loginName,
        passwd: this.password
      }
      Api.http
        .post(Api.url.login, paramLogin)
        .then(function(result) {
          if (result.code !== 0) {
            Vue.$vux.alert.show({
              title: '视频投票 - 错误提示',
              content: result.msg
            })
          } else {
            vue.$store.commit('changeToken', result.token)
            vue.$store.commit('changeUser', result.user)
            vue.$router.push({
              name: 'vote_list'
            })
          }
        })
        .catch(function(message) {})
    }
  }
}
</script>

<style>
@import '../style/main.less';
.vux-demo {
  margin: 20px;
  text-align: center;
}
.logo {
  width: 100px;
  height: 100px;
}
</style>
